home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Leser 15
/
Amiga Plus Leser CD 15.iso
/
Tools
/
Development
/
PluginSRC_EvenMore
/
wordwrap2.e
< prev
Wrap
Text File
|
2002-03-12
|
3KB
|
142 lines
/*
MSWord2Text
EvenMore FileIO plugin
Author: Chris Perver
Copyright (c) 2001
*/
OPT REG=5
LIBRARY 'wordwrap.plugin',1,1,'Wordwrap 1.01' IS em_main, em_end, em_info, em_pluginid, em_begin, em_format
MODULE 'tools/ctype', '*epo'
DEF mem2:PTR TO CHAR->, mswvers
PROC em_isdatatype(memadr, lenadr)
DEF c = 0, linewidth = 0, newlines = 0
-> FIND IF WE ACTUALLY NEED TO WORDWRAP THIS FILE
WHILE (c < lenadr)
SELECT 256 OF memadr[c]
CASE "\e"
IF memadr[c + 1] = "["
c := c + 2
WHILE ((memadr[c] >= $30) AND (memadr[c] <= $3B))
INC c
ENDWHILE
ENDIF
INC c
CASE "\n"
linewidth := 0
CASE "\b"
IF memadr[c+1] = "\n" THEN INC c
linewidth := 0
DEFAULT
INC linewidth
IF (linewidth > 81)
INC newlines
linewidth := 0
ENDIF
ENDSELECT
INC c
ENDWHILE
ENDPROC newlines
PROC em_parsedata(epo:PTR TO em_pluginobj)
DEF memadr:PTR TO CHAR, lenadr
DEF count = 0, count2 = 0
DEF currchar = 0
DEF notdone = TRUE
DEF wordwrap = 81, oldpos, oldcc
memadr := epo.buffer
lenadr := epo.length
mem2 := epo.nbuffer
notdone := TRUE
WHILE notdone AND (count < lenadr)
SELECT 256 OF memadr[count]
CASE "\e"
IF memadr[count + 1] = "["
mem2[count2++] := memadr[count++]
mem2[count2++] := memadr[count++]
WHILE ((memadr[count] >= $30) AND (memadr[count] <= $3B))
mem2[count2++] := memadr[count++]
-> INC charcount
ENDWHILE
ENDIF
->INC charcount
mem2[count2++] := memadr[count]
CASE "\b", "\n"
mem2[count2++] := memadr[count]
currchar := 0
DEFAULT
mem2[count2++] := memadr[count]
INC currchar
IF currchar >= wordwrap
-> Find last space
IF isspace(mem2[count2]) = TRUE
mem2[count2++] := "\n"
currchar := 0
ELSE
oldpos := count2
oldcc := currchar
WHILE isspace(mem2[count2]) = FALSE
mem2[count2 + 1] := mem2[count2]
DEC count2
DEC currchar
ENDWHILE
INC count2
mem2[count2] := "\n"
currchar := oldcc - currchar
count2 := oldpos + 1
ENDIF
ENDIF
ENDSELECT
INC count
ENDWHILE
mem2[count2] := "\n"
ENDPROC mem2, count2
-><
-> *** STANDARD PROCS FOR PLUGINS
PROC em_main(epo:PTR TO em_pluginobj)
DEF len2
mem2, len2 := em_parsedata(epo)
epo.nlength := len2
RETURN TRUE
ENDPROC
PROC em_begin(epo:PTR TO em_pluginobj)
DEF extralines
extralines := em_isdatatype(epo.buffer, epo.length)
IF extralines > 0
RETURN "MEM", (epo.length * 2)
ELSE
RETURN FALSE
ENDIF
ENDPROC
PROC em_end() IS EMPTY
PROC em_info() IS 'Wordwrap 1.01'
PROC em_pluginid() IS "FRMT"
PROC em_format() IS 'Wordwrap'
PROC main() IS EMPTY